package com.ftg.learn.chapter12.springbootdemo.mapper;

import com.ftg.learn.chapter12.springbootdemo.entity.UserEntity;
import com.ftg.learn.chapter12.springbootdemo.util.R;
import com.ftg.learn.chapter12.springbootdemo.vo.UserVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 描述
 *
 * @author 布衣
 * @date 2024/9/23
 */
@Mapper
public interface UserMapper {

    @Select("select id,username,realname,case gender when 0 then '男' when 1 then '女' else '保密' end gender,phone,create_time,info from user")
    List<UserVo> list();

    @Select("select id from user where username = #{username} and password = #{password}")
    Integer login(@Param("username") String username, @Param("password") String password);

    @Select("select id,username,realname,case gender when 0 then '女' when 1 then '男' else '保密' end gender,phone,create_time,info from user where id = #{id}")
    UserVo getUserInfoById(@Param("id") Integer id);

    @Select("select id,username,password from user where id = #{id}")
    UserEntity findOneById(Integer id);

    @Update("update user set password = #{newpasswrod} where id = #{id}")
    int modifyPassword(@Param("id") Integer id,@Param("newpassword") String newpasswrod);

    @Insert("insert into user(userno_id,username,password,realname,gender,phone,create_time,info) values(1,#{username},#{password},#{realname},#{gender},#{phone},#{create_time},#{info})")
    Integer save(UserEntity ue);

    @Update("update user set username=#{username},realname=#{realname},gender=#{gender},phone=#{phone} where id = #{id}")
    Boolean modify(UserVo ue);

    @Delete("delete from user where id = #{id}")
    Boolean delById(@Param("id") Integer id);
}
